﻿using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Web;
using System.Web.Mvc;

namespace visu.Controllers.v1
{
    public class cabinetController : Controller
    {
        //
        // GET: /cabinet/

        public ActionResult status()
        {
            var tempObj = new object();
            Stream postData = Request.InputStream;
            StreamReader sRead = new StreamReader(postData);
            string postContent = sRead.ReadToEnd();
            if(postContent=="")
            {
                tempObj = new { code = "error", data = "", message = "输入参数不正确！" };
                return Json(tempObj, JsonRequestBehavior.AllowGet);
            }
            Dictionary<string, object> suggestions = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, object>>(postContent);

            if (suggestions.Keys.Contains("device_id") && suggestions["device_id"].ToString()!="")
            {
                string DEVICE_ID = suggestions["device_id"].ToString();
                string sql = "SELECT [CAB_ID],[PRODUCT_ID],[PRODUCT_NO],[DEVICE_ID],[PRODUCT_NAME],[CAB_NAME],[CAB_CODE],[CAB_MARTERIAL_NUMBER],[CAB_TYPE],[INVENTORY_NUMBER],[M_CODE],[M_SPECIFICATION],[M_IMGURL],[M_TYPE] FROM [dbo].[vcabinetmaterial] where CAB_STATUS='0' AND DEVICE_ID='" + DEVICE_ID + "' AND ISNULL(CAB_MARTERIAL_ID,'')!='' ORDER BY CAB_NAME";
                DataTable dt = DBCallCommon.GetDTUsingSqlText(sql);
                if (dt.Rows.Count > 0)
                {
                    var data = Commons.Serialize(dt);
                    tempObj = new { code = "success", data = data, message = "查询成功！" };
                }
                else
                {
                    tempObj = new { code = "success", data = "", message = "未查询到记录！" };
                }

                return Json(tempObj, JsonRequestBehavior.AllowGet);
            }
            else
            {
                tempObj = new { code = "error", data = "", message = "设备号不能为空！" };
                return Json(tempObj, JsonRequestBehavior.AllowGet);
            }

        }

    }
}
